﻿// JavaScript Document

var isLock=true;var strLoading='<div align=center><img src="images/loading.gif"   alt="正在加载" /><br>正在努力加载中，请稍候……</div>';
var strEnter=String.fromCharCode(13);
//按id返回对象
function oid(id){return document.getElementById(id);}
//弹出对话框
function Alert1(msg){window .alert (msg);}
//返回上一页
function goBack(){window.history.go(-1);}
//跳转到网页
function goUrl(u){window.location.href=u;}
//确认对话框
function Confirm(v){if(confirm(v)){return true}else{return false}}
//超时退出
function hTimeout(){alert("对不起！您的登陆已超时，请重新登陆。");top.location.href='default.aspx';}
function setTBHeight(tbid){	var tb=document.getElementById(tbid);}
//关闭窗口
function Close(){window.close();}
//显示日期选择器
function showDatetime(divId,dcId,dtId,l,t){
	var div=document.getElementById(divId);
	var dc=document.getElementById(dcId);
	var dt=document.getElementById(dtId);
	
	if(div !=null){
		if(l!=null){ div.style.left=l+'px';}
		if(t!=null){ div.style.top=t+'px';}
		div.style.display='';
	}
	oid("setDateID").value=dtId;
	dc.value=dt.value;
	//alert("b")
}
//关闭显示
function hideControl(o){var obj=document.getElementById(o);	if(obj !=null){obj.style.display='none'}}
//开启象显示
function showControl(o){var cloObj=document.getElementById(o);	if (cloObj!=null){cloObj.style.display='block'}}
//去掉HTML标签
function getInnerText(v){return v.replace(/(<(.[^>]*)>)|(&nbsp;)/g,"");}
//去前后空格
function trim(str){return str.replace(/^\s+|\s+$/g,""); }
//替换千分号字符
function delQChar(t){if(t){t.value=t.value.replace(/[,]/g,''); }}
//去掉回车换行
function delEnterline(str){	return str.replace(/[\r\n]/g,'');}
//替换回车换行符 
function replaceEnter(str){	return str.replace(/[\r\n]/g,'/EnterChar/');}
//还原回车换行符 
function restoreEnter(str){	var reg=new RegExp('/EnterChar//EnterChar/','g');	return str.replace(reg,strEnter);}
//删除空行
function delEmptyLine(str){
	var strLines=str.split(strEnter),nstrLines='',strLine='';
	for(var li=0;li<strLines.length;li++){
		strLine=strLines[li];
		if(trim(strLine) !=''){if(nstrLines==''){nstrLines=strLine}else{nstrLines +=strEnter+strLine;}}
	} return nstrLines;
}
//输入时限制回车换行符，v要替换的字符编码
function replaceEnterKeycode(v){if(v==''){v=0;}	if(event.keyCode==13){event.keyCode=v;}}
//检测Script标签
function checkScriptCode(v){
	var v1=trim(v),chkStr=new Array('<%','<script','<!--#include'),ii=0,vi=-1; 
	for(ii=0;ii<chkStr.length;ii++){vi=v1.indexOf(chkStr[ii]);if(vi==0){break}	}
	if(vi==0){return '&nbsp;'+v;}else{return v;}}

function loading(dv){
	var div=oid(dv);
	if(div!=null){div.innerHTML=strLoading;}
}

function openUpload(pg,w,h,scrb,fid,pid,sp,mul){
	window.open(pg+'?ufid='+fid+'&savp='+sp+'&imgid='+pid+'&mul='+mul,'uploadpg','width='+w+',height='+h+',scrollbars='+scrb);
	//return false;
}
function clearUpload(fid,pid){
	oid(fid).value='';
	if(pid!=''){oid(pid).src=''};
}


//导出Excel
function toExcel(tid,nc){ 
	//copy(tabid); 
	var tabid=document.getElementById(tid);
	if(tabid==null){alert('要导出的表格对象不存在，导出已取消！');return false}
	try{ 
		var xls = new ActiveXObject( "Excel.Application" ); 
	}catch(e){ 
		alert( "Excel没有安装或浏览器设置不正确.请按下列步骤启用相关的Active控件和插件!\n Internet选项 > 安全 > 自定义级别。\n 将Active控件和插件相关的设置为启用或提示（在使用时会弹出对话框询问是否启用，请点是）即可。"); 
		return false; 
	} 
	xls.visible = true; 
	//var cw=new Array(5,20,10,15,15,10,10,10,10,50); //毫米
	var xlBook = xls.Workbooks.Add; 
	var xlsheet = xlBook.Worksheets(1); 
	xlBook.Worksheets(1).Activate; 
	var tdCell,tdVal='';
	var nnc=nc||1
	for(var r=0;r<tabid.rows.length;r++){ 
		for(var c=0;c<=tabid.rows(0).cells.length-nnc;c++){
			tdCell=tabid.rows(r).cells(c);
			tdVal=tdCell.innerHTML;
			//if(r==0){xlsheet.Columns(c+1).ColumnWidth=parseInt(tdCell.width/8);}    ///设置列宽 毫米
			//xlsheet.Rows(i+1).RowHeight=120;	//设置行高 像素
			//xlsheet.Cells(r+1,c+1).Interior.color =tdCell.bgcolor;
			xlsheet.Cells(r+1,c+1).Value=getInnerText(tdVal);
		}
	}
	xlsheet.Columns.AutoFit; 
	//xlsheet.Paste; 
	xls=null;  
	//idTmr = window.setInterval("Cleanup();",1); 
} 

//内容页ajax加载函数
//url:请求地址；div：显示数据控件ID
function ajaxGetRequest(url,div){
	var i=Math.random();var sjcs="&i="+i;
	if (url.indexOf("?")==-1){sjcs="?i="+i}
	$.get(url+sjcs,function(data){
		$("#"+div).html(data);
		
		})
	}
//只允许输入数字与小数点   
function checkkey(value,e){   
	var key = window.event?e.keyCode:e.which; 
            if( (key > 95 && key < 106) ||   
                (key >47 && key <58) || (key==109 ||key==189) || 
                (key == 110 && value.indexOf(".") < 0 )||   
                (key == 190 && value.indexOf(".") < 0 )|| key==9){   
            }else if(key !=8){   
                if (window.event){ //IE   
                    e.returnValue = false;   //event.returnValue=false 效果相同.   
                }else{ //Firefox   
                    e.preventDefault();   
                }   
            }   
}   
//只允许输入数字   
function checkkey2(value,e){   
	var key = window.event?e.keyCode:e.which;   
	if( (key > 95 && key < 106) || (key > 47 && key < 60)){   
	}else if(key !=8 || key !=45){   
		if (window.event) //IE   
		{   
			e.returnValue = false;   //event.returnValue=false 效果相同.   
		}   
		else //Firefox   
		{   
			e.preventDefault();   
		}   
	}   
}   
//检测对象为空时赋默认值
function checkNum(t,v){
	if(t.value==''){t.value=v}
}
//确认删除信息	
function delconfirm(chkid){
	if(isCheckOne(chkid)==false){alert('请至少选择一个要删除的项');return false}
	return Confirm('确定要删除选中的项吗？')
}
//全选
function checkAll(chkid,v){
	var chk=null;
	var i=0;
	do{
		chk=document.getElementById(chkid+i);
		if(chk!=null){chk.checked=v}
		i+=1;
	}while(chk!=null)
}
//是否至少选择了一项
function isCheckOne(chkid){
	var chk=null;
	var i=0;
	do{
		chk=document.getElementById(chkid+i);
		if(chk!=null){if(chk.checked==true){return true}}
		i+=1;
	}while(chk!=null)
	return false;
}
//设置选项值
function setCheckValue(chkid,tid){
	var chk=null;
	var i=0,vals='',v=0;
	do{
		chk=document.getElementById(chkid+i);
	
		if(chk!=null){
			//alert(chk.id + ':'+ chk.checked)
			if(chk.checked==true){v=1}else{v=0}
			if(i==0){vals=v}else{vals+=','+v}
		}
		i+=1;
	}while(chk!=null)
	 document.getElementById(tid).value=vals;
	 //alert(vals)
}
//获取选中的值
function getCheckValues(chkid,ov){
	var chk=null;
	var i=0,vals='',v=0;
	do{
		chk=document.getElementById(chkid+i);
	
		if(chk!=null){
			//alert(chk.id + ':'+ chk.checked)
			if(chk.checked==true){
				v=chk.value;
				if(vals==''){vals=ov+v}else{vals+=','+ov+v}
			}
		}
		i+=1;
	}while(chk!=null)
	 return vals;
	 //alert(vals)
}

//日期控件函数
//tagSelect:绑定控件选择器,yearRange:年范围，如：1999:2013
function showDatePicker(tagSelect, yearRange, icon) {
    if (yearRange == "" || !yearRange) { yearRange = "2003:2023" }
    if (icon == "") {
        $(".datepicker").datepicker({
            changeMonth: true, changeYear: true, showAnim: "clip", dateFormat: "yy-mm-dd", showButtonPanel: true,
            yearRange: yearRange
        })
    } else {
        $(".datepicker").datepicker({
            changeMonth: true, changeYear: true, showAnim: "clip", dateFormat: "yy-mm-dd", showButtonPanel: true,
            yearRange: yearRange, showOn: "button", buttonImage: "images/date.gif", buttonImageOnly: true
        })
    }
}


//设置Cookie ;s20是代表20秒
    //h是指小时，如12小时则是：h12
    //d是天数，30天则：d30
    function setCookie(name, value, time) {
        var strsec = getsec(time);
        var exp = new Date();
        exp.setTime(exp.getTime() + strsec * 1);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
    }

    function getsec(str) {
        var str1 = str.substring(1, str.length) * 1;
        var str2 = str.substring(0, 1);
        if (str2 == "s") {
            return str1 * 1000;
        }
        else if (str2 == "h") {
            return str1 * 60 * 60 * 1000;
        }
        else if (str2 == "d") {
            return str1 * 24 * 60 * 60 * 1000;
        }
    }
    
    //获取Cooke
    function getCookie(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

        if (arr = document.cookie.match(reg))

            return (unescape(arr[2]));
        else
            return null;
    }

    //删除cookies
    function delCookie(name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = getCookie(name);
        if (cval != null)
            document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
	
	//搜索框样式变换
function setSery(t,dfv){
	if(t.value==dfv){t.value='';t.style.color='#333333'}
}
function resSery(t,dfv){
	if(t.value==''){t.value=dfv;t.style.color='#cccccc'}
}
function submitSerkey(){
	var frm1=document.getElementById("form1");
	if(frm1 !=null){
	var sk=document.getElementById("webTop_serKey");
	if(sk.value=='' || sk.value=='产品名称或型号'){alert('请输入有效的关键词再搜索！');return false;}	
	frm1.action="product.aspx";
	frm1.submit();
	}
}